﻿using MusicZone.Data;
using MusicZone.EnableLiveTile;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Grouped Items Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234231

namespace MusicZone
{
    /// <summary>
    /// A page that displays a grouped collection of items.
    /// </summary>
    public sealed partial class HubPage : MusicZone.Common.LayoutAwarePage
    {
        public HubPage()
        {
            this.InitializeComponent();
            TopAppBar.AppBarTop20.Click += AppBarTop20_Click;
            TopAppBar.AppBarArtists.Click += AppBarArtists_Click;
        }

        void AppBarTop20_Click(object sender, RoutedEventArgs e)
        {
            this.Frame.Navigate(typeof(Spoke1), "AllGroups");
        }

        void AppBarArtists_Click(object sender, RoutedEventArgs e)
        {
            this.Frame.Navigate(typeof(Spoke2), "AllGroups");
        }

        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
        {
            CreateLiveTile.ShowliveTile(true, "Music Template");
            var HubPageDataGroups = HubPageDataSource.GetGroups((String)navigationParameter);
            this.DefaultViewModel["Groups"] = HubPageDataGroups;

            var SemanticDataGroups = SemanticDataSource.GetGroups((String)navigationParameter);
            this.DefaultViewModel["Groups2"] = SemanticDataGroups;
            
        }
      

       
        private void Header_Tapped(object sender, TappedRoutedEventArgs e)
        {
            Zoom.ZoomedInView.IsActiveView = true;
        }

        private void Header_Click(object sender, RoutedEventArgs e)
        {
            if (e == null)
                return;
            if (e.OriginalSource == null)
                return;
            Button Header = new Button();
            if (e.OriginalSource is Button)
                Header = e.OriginalSource as Button;

            if (Header.Tag == "Group-1")
                this.Frame.Navigate(typeof(Spoke1), "AllGroups");

            if (Header.Tag == "Group-3")
                this.Frame.Navigate(typeof(Spoke2), "AllGroups");
        }

        private void SemanticGridview_Click(object sender, ItemClickEventArgs e)
        {
            if (e == null)
                return;
            SemanticDataItem data = null;
            if (e.ClickedItem is SemanticDataItem)
                data = e.ClickedItem as SemanticDataItem;
            if (data != null && data.UniqueId.StartsWith("Group-1-Item-1"))
                MainScroll.ScrollToHorizontalOffset(0);
            if (data != null && data.UniqueId.StartsWith("Group-1-Item-2"))
                MainScroll.ScrollToHorizontalOffset(940);
            if (data != null && data.UniqueId.StartsWith("Group-1-Item-3"))
                MainScroll.ScrollToHorizontalOffset(1350);
            if (data != null && data.UniqueId.StartsWith("Group-1-Item-4"))
                MainScroll.ScrollToHorizontalOffset(1870);
            if (data != null && data.UniqueId.StartsWith("Group-1-Item-5"))
                MainScroll.ScrollToHorizontalOffset(2250);
            if (data != null && data.UniqueId.StartsWith("Group-1-Item-6"))
                MainScroll.ScrollToHorizontalOffset(3000);

            Zoom.IsZoomedInViewActive = true;
        }

       
       
    }
}
